# Expected vars
# - name...
# - cert_name...
# - server_aliases: []
# - server_admin: webmaster@fedoraproject.org
# - ssl: true
# - sslonly: false
# - SSLCertificateChainFile: ""
# - gzip: false

- name: Create site directory in httpd/conf.d/{{name}}
  file: >
    dest=/etc/httpd/conf.d/{{name}}
    state=directory
    owner=root
    group=root
    mode=0755
  notify:
  - reload httpd
  tags:
  - httpd
  - httpd/website

# TODO - copy in Httpd::Certificate

- name: Copy over primary template for {{name}}
  template: >
    src=website.conf
    dest=/etc/httpd/conf.d/{{name}}.conf
    owner=root
    group=root
    mode=0644
  notify:
  - reload httpd
  tags:
  - httpd
  - httpd/website

- name: Copy over some subordinate templates for {{name}}
  template: >
    src={{item}}.conf
    dest=/etc/httpd/conf.d/{{name}}/{{item}}.conf
    owner=root
    group=root
    mode=0644
  with_items:
  - logs
  - robots
  notify:
  - reload httpd
  tags:
  - httpd
  - httpd/website

- name: And lastly, the robots.txt file
  copy: >
    src={{item}}
    dest=/srv/web/robots.txt.{{name}}
    mode=0644
    owner=root
    group=root
    setype=httpd_sys_content_t
  with_first_found:
  - robots/robots.txt.{{name}}
  - robots/robots.txt
  notify:
  - reload httpd
  tags:
  - httpd
  - httpd/website
